﻿using HoverTree.BLL;
using HoverTree.HoverTreeFrame;
using HoverTree.HoverTreeFrame.HvtImage;
using HoverTree.Model;
using System;

namespace HoverTreeWeb.HVTPanel.HPicture
{
    public partial class AddPicture : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int m_imageSetID = RequestHelper.GetQueryInt("isid", 0);
                if (m_imageSetID < 1)
                {
                    ltlTips.Text = "图集不存在";
                    btnSubmit.Enabled = false;
                    return;
                }

                ImageSetInfo m_isInfo = new ImageSetInfo();
                HvtImageSet m_bll = new HvtImageSet();
                m_isInfo= m_bll.GetByID(m_imageSetID);
                if(m_isInfo==null)
                {
                    ltlTips.Text = "图集不存在";
                    btnSubmit.Enabled = false;
                    return;
                }

                ltlImageSetID.Text = m_isInfo.HvtID.ToString();
                ltlImageSetTitle.Text = m_isInfo.HvtTitle;

            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            PictureInfo m_picInfo = new PictureInfo();
            m_picInfo.HvtIshome = cbIshome.Checked;
            m_picInfo.HvtIsshow = cbIsshow.Checked;
            m_picInfo.HvtTitle = tbTitle.Text.Trim();
            m_picInfo.HvtNote = tbNote.Text;
            m_picInfo.HvtLink = txtLink.Text;
            m_picInfo.HvtIsTop = cbIstop.Checked;
            m_picInfo.HvtImageSetId = Convert.ToInt32(ltlImageSetID.Text);

            HvtPicture m_bll = new HvtPicture();

            HvtPicConfig m_config = new HvtPicConfig();
            m_config.WaterMark = cbIsWaterMark.Checked;
            m_config.ListWaterMark = cbListWaterMark.Checked;
            ltlTips.Text = m_bll.Add(m_picInfo, fuPicture,m_config);

            if (ltlTips.Text == string.Empty)
            {
                ltlTips.Text = "添加成功";
                ResetInput();

                PictureSelect m_select = new PictureSelect();
                m_select.HvtFileName = m_picInfo.HvtFilename;
                m_select.HvtIsShow = 1;

                m_picInfo = m_bll.Get(m_select);

                ltlTips.Text = ltlTips.Text + m_bll.GenerateNewAdd(m_picInfo);
            }
        }

        private void ResetInput()
        {
            tbNote.Text = string.Empty;
            tbTitle.Text = string.Empty;
            cbIsshow.Checked = true;
            cbIshome.Checked = false;
        }
    }
}